define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'chatroom/index' + location.search,
                    add_url: 'chatroom/add',
                    edit_url: 'chatroom/edit',
                    del_url: 'chatroom/del',
                    multi_url: 'chatroom/multi',
                    import_url: 'chatroom/import',
                    table: 'chat_room',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), operate: 'false'},
                        // {field: 'user_id', title: __('User_id')},
                        // {field: 'to_id', title: __('To_id')},
                        // {field: 'information_id', title: __('Information_id'), searchList: {"1":__('Information_id 1'),"0":__('Information_id 0'),"P":__('Information_id p')}, formatter: Table.api.formatter.normal},
                        // {field: 'is_margin', title: __('Is_margin'), searchList: {"1":__('Is_margin 1'),"2":__('Is_margin 2')}, formatter: Table.api.formatter.normal},
                        {field: 'group_type', title: __('Group_type'), searchList: {"1":__('Group_type 1'),"2":__('Group_type 2'),"3":__('Group_type 3'),"4":__('Group_type 4')}, formatter: Table.api.formatter.normal},
                        {field: 'information_id', title: __('信息名称'), operate: 'LIKE'},
                        // {field: 'group_room', title: __('Group_room'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2'),"3":__('Type 3')}, formatter: Table.api.formatter.normal},
                        // {field: 'number', title: __('Number')},
                        // {field: 'content', title: __('Content'), operate: 'false'},
                        {field: 'titlestr', title: __('联系人'), operate: 'LIKE'},
                        {field: 'last_time', title: __('Last_time'), operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'add_time', title: __('Add_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'user.username', title: __('User.username'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'user.tel', title: __('User.tel'), operate: 'LIKE'},
                        // {field: 'user.username', title: __('User.username'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'user.tel', title: __('User.tel'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, 
                        buttons: [
                            {
                                name: 'edit',
                                text: __('查看聊天'),
                                title: __('查看聊天'),
                                classname: 'btn btn-xs btn-primary btn-dialog',
                                icon: 'fa fa-list',
                                extend: 'data-area=\'["90%", "80%"]\'',
                                url: 'chatgroupcontent/index',
                            }
                            
                        ], 
                        formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
